#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int a[N];
ll sum[N], f[N];
ll g(int i) { return f[i] - sum[i + 1]; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) sum[i] = sum[i - 1] + a[i];
  deque<int> dq;
  int pos = 0;
  rep(i, 1, min(n, m)) f[i] = sum[i];
  rep(i, m + 1, n) {
    // unsel
    f[i] = f[i - 1];
    // sel j .. i  i + 1 - k <= j <= i
    int L = i + 1 - m - 2, R = i - 2;
    while (pos <= R) {
      while (dq.size() && g(dq.back()) <= g(pos)) dq.pop_back();
      dq.push_back(pos++);
    }
    while (dq.size() && dq.front() < L) dq.pop_front();
    f[i] = max(f[i], g(dq.front()) + sum[i]);
  }
  cout << f[n];
  return 0;
}